const nunjucks = require("nunjucks");
const path = require("path");
const fs = require("fs");

// 指定文件名
const name = process.argv[2];

// console.log(1, name, name.charAt(0), name.slice(1))

// 接口名称
const interfaceName = `${name.charAt(0).toUpperCase() + name.slice(1)}Model`;

// 模型名称
const modelName = `${name.toUpperCase()}_MODEL`;

function getFileHeaderTmpl() {
    return   `/**
*
* 生成相关常量model 信息，初始化数据结构
* 规定函数形状
*
* @interface {{interfaceName}}
*/
   
interface {{interfaceName}} {
    
}

const {{modelName}}: {{interfaceName}}= {

}

export default {{modelName}};`;
}

const renderString = nunjucks.renderString(getFileHeaderTmpl(), {
    interfaceName: interfaceName,
    modelName: modelName
})

const pathOfFile = path.resolve(__dirname, `${name}.model.ts`);
const fileExist = fs.existsSync(pathOfFile);
if (!fileExist) {
    fs.writeFileSync(pathOfFile, renderString)
} else {
    console.log("> file is already exist ! 🤪")
}
